(function ($) {
	var timer;
	var examInfo;
	var queDict;
	var currPage=0;//当前是第几题
	var currSlideIndex = 0;
	var pageCount = 0;
	var pageType = '';//practice随堂练习 classEndExam结课考核和去考核 analy解析  chapter章节练习
	var fromPage = ''
	var isAnaly = false,allAnaly=false;
	var nurseid = '',rw='',typeFlag = ''
	var quesType={'S':'单选题','M':'多选题','B':'填空题','A':'问答题'}
	var splitStr = '」' //多选和填空的分隔符
	$.init();
	$.plusReady(function () {
	    baseSetup();
	})
	
	//保存答案
	function saveAllAnswer(){
		var ExamTimeDom = mui('#reduceTime')[0]
		var initTime = timeToSecond(ExamTimeDom.getAttribute('data-init'))
		var nowTime = timeToSecond(ExamTimeDom.innerText)
		var ExamTime = secondToTimeStr(initTime - nowTime)
		examInfo['ExamTime'] = ExamTime
		if (fromPage == 'toExamine') {
			mui.toast('缺少保存接口') //PC端是单个保存 接口SaveExamTheory  GetOperationCheck
			var fromWebview = plus.webview.getWebviewById(fromPage)
			fromWebview.evalJS("refreshExamineUI("+JSON.stringify(examInfo)+","+JSON.stringify(queDict)+")")
			plus.webview.currentWebview().close();
			return
		}
		//parr: 26||8「011「0」26||9「0111111「1」26||10「011111111111111「填空1,填空2,填空3」26||11「0111「2」26||12「01「3」26||13「011「0」
		//26||14「011「1」26||15「01111「2」26||16「0111111111「填空1,填空2,填空3
		var parr = '' ;
		for (var i = 0; i < queDict.length;i++) {
			var oneDict = queDict[i]
			if (i != 0) {
				parr += '」'
			}
			parr += oneDict['SubRw']+'「'+ExamTime+'「'+oneDict['Result']
		}
		//console.log(parr)
		//return
		var pdict = {'parr':parr,'rw':rw,'ExamTime':ExamTime}
		var paramDict = {'method':'web.INMTeaComm:SaveLearnDryRunSub','params':JSON.stringify(pdict),'type':'Method'}
		$.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			var arr = result.msg.split('^')
			if (arr[0] == '0') {
				mui.toast(arr[1])
				return
			}
			isAnaly = true
			if (fromPage != 'toExamine') {
				getExamineData()
			}
		}, function(errorStr) {
			mui.toast('请重试')
		});
	}
	function saveToTrainClass(){
		var ExamTimeDom = mui('#reduceTime')[0]
		var initTime = timeToSecond(ExamTimeDom.getAttribute('data-init'))
		var nowTime = timeToSecond(ExamTimeDom.innerText)
		var ExamTime = secondToTimeStr(initTime - nowTime)
		var subParr = '' ;
		for (var i = 0; i < queDict.length;i++) {
			var oneDict = queDict[i]
			if (i != 0) {
				subParr += '「'
			}
			subParr += '^'+oneDict['SubRw']+'^'+oneDict['Result']+'^'+oneDict['ExamScore']
		}
		//subParr: ^3||1^4^10「^3||16^1^10「^3||2^4^10「^3||3^4^10「^3||4^4^10
		var parr= typeFlag+'^'+examInfo['subID']+'^'+ExamTime+'^'
		var pdict = {'parr':parr,'subParr':subParr}
		var paramDict = {'method':'web.INMTeaComm:SaveDrillTheory','params':JSON.stringify(pdict),'type':'Method'}
		$.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			//success^3||1,3||18||5,0「3||16,3||18||6,0「3||2,3||18||7,0「3||3,3||18||8,0「3||4,3||18||9,0
			var arr = result.msg.split('^')
			if (arr[0] != 'success') {
				mui.toast(arr[1])
				return
			}
			var queArr = arr[1].split('「')
			var rightCount = 0
			for (var i = 1; i < queArr.length; i++) {
				var flag = queArr[i].split(',')[2]||''+''
				if (flag == '1') {
					rightCount += 1
				}
			}
			var str = '答对'+rightCount+'道题，答错'+(queDict.length-rightCount)+'道题，用时 '+ExamTime
			var fromWebview = plus.webview.getWebviewById(fromPage)
			fromWebview.evalJS("setToTrainInfo('"+str+"','"+typeFlag+"')")
			plus.webview.currentWebview().close();
		}, function(errorStr) {
			mui.toast('请重试')
		});
	}
	function getExamineData(){
		var pdict = {'parr':rw}
		var method = 'web.INMTeaComm:FindLearnDryRunSubList'
		if (fromPage == 'toExamine') {
			method = 'web.INMTeaComm:FindExamProblemList';
			pdict['UserId'] = nurseid
		}else if (fromPage == 'toTrain'){
			method = 'web.INMTeaComm:FindDrillProblemList';
			if (isAnaly) {
				method = 'web.INMTeaComm:FindDrillTheoryList'
			}
			pdict = {'parr':examInfo['subID']+'^'+typeFlag}
		}
		//console.log(JSON.stringify(pdict))
		var paramDict = {'method':method,'params':JSON.stringify(pdict),'type':'RecQuery'}
		$.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			if (result.msgcode != '1') {
				mui.toast('失败')
				return
			}
			if (!queDict) {
				updateCommitPopoUI(result['data'].length)
			}
			if (isAnaly && !allAnaly) {
				var arr = result['data']
				queDict = []
				if (fromPage == 'toTrain') {
					for (var i = 0; i < arr.length; i++) {
						if (arr[i]['CorrectFlag'] != '1') {
							queDict.push(arr[i])
						}
					}
				}else{ //GetScore
					for (var i = 0; i < arr.length; i++) {
						if (arr[i]['GetScore'] != arr[i]['ExamScore']) {
							queDict.push(arr[i])
						}
					}
				}
			}else{
				queDict = result['data']
			}
			if (fromPage == 'toTrain' || !isAnaly) {
				updateExamUI()
			}else if(isAnaly && fromPage != 'toExamine'){
				updateScoreInfo()
			}
		}, function(errorStr) {
		 	
		});
	}
	
	function updateExamUI(){
		if (!queDict || queDict.length == 0) {
			mui.toast('未获取到考题')
			return
		}
		if (!isAnaly) {
			setupTimer()
		}
		pageCount = queDict.length
		var num = 3
		if (pageCount < num) {
			num = pageCount
		}
		for(var i = 0; i < num;i++){
			updateOneQuesUI(i)
		}
		if ($('#0')[0]) {
			$('#0')[0].classList.add('mui-active')
		}
		if (!isAnaly) {
			$('#item-0')[0].classList.add('dhc-active')
		}
		console.log(mui('#slider')[0].innerHTML)
		mui('#slider').slider().refresh();
		currSlideIndex = 0;
		currPage = 1;
		$('#currPage')[0].innerHTML = currPage;
		$('#pageCount')[0].innerHTML = pageCount;
	}
	
	function updateOneQuesUI(index,prePageDom){
		clearAllBtnTapped(index)
		var sliderItem = $('#'+index)[0]
		if (!sliderItem) {
			sliderItem = document.createElement('div')
			
			if (prePageDom) {
				$('#loop')[0].insertBefore(sliderItem,prePageDom);
			}else{
				$('#loop')[0].appendChild(sliderItem)
			}
			sliderItem.setAttribute('class','mui-slider-item')
			sliderItem.id = index
			sliderItem.innerHTML = '<div class="mui-scroll-wrapper"><div class="mui-scroll"></div></div>'
		}
		var oneDict = queDict[index]
		var type = oneDict['SubMode']; //S单选 M多选 B填空 A问答
		var title = oneDict['SubDesc'];
		var sub = oneDict['SubSource'];
		if (type == 'B') {
			var arr = title.split('﹏﹏')
			title = ''
			for (var i= 0; i < arr.length;i++) {
				title += arr[i]
				if (i != arr.length - 1) {
					title += '<div class="blank">（'+(i+1)+'）</div>'
				}
			}
		}
		var html = '<div class="examTitle">'+(index+1)+'、<span class="examType">【'+quesType[type]+'】</span>'+title
		if(sub != ''){
			html += '<span class="subText">（'+sub+'）</span>'
		}
		if (type == 'A') {
			html += '<span class="askText">（人工阅卷）</span>'
		}
		html += '<span class="scoreText">（'+oneDict['ExamScore']+'分）</span></div>';
		
		var muiScroll = sliderItem.querySelector('.mui-scroll')
		muiScroll.setAttribute('data-type',type)
		muiScroll.innerHTML = html
		switch (type) {
			case 'S':
				createRadioUI(oneDict,muiScroll,index);
				break;
			case 'M':
				createCheckboxUI(oneDict,muiScroll,index);
				break;
			case 'B':
				createMultiBlankUI(oneDict,muiScroll,index);
				break;
			case 'A':
				createAskUI(oneDict,muiScroll,index);
				break;
		}
	}
	
	// 单选
	function createRadioUI(oneDict,scrollDom,index){
		scrollDom.classList.remove('analysisMode')
		var option = oneDict['SubOption'].split('」')
		var optionsArea = document.createElement('div');
		optionsArea.id = 'ques-'+index
		optionsArea.classList.add('optionsArea');
		scrollDom.appendChild(optionsArea);
		
		var html = ''
		var nurAns = oneDict['Result']
		for(var i= 0; i < option.length;i++){
			var op = option[i];
			var activeClass=''
			if(nurAns!="" && i == nurAns){
				activeClass='dhc-active'
			}
			var str = String.fromCharCode(64 + parseInt(i+1));
			html += '<div class="option '+activeClass+'">'+
				'<div class="opName nurfont" data-op="'+i+'">'+str+'</div>'+
				'<div class="opTitle">'+op+'</div></div>'
		}
		optionsArea.innerHTML = html;
		if (!isAnaly) {
			var options = optionsArea.querySelectorAll('.option');
			for (var i = 0; i < options.length;i++) {
				options[i].addEventListener('tap',radioOptionTapped);
			}
		}else{//解析部分
			radioOptionAddAnaly(optionsArea,scrollDom,index);
		}
	}
	function radioOptionTapped(){
		var opDom = this
		var parentNode = opDom.parentNode
		var oldActive = parentNode.querySelector('.dhc-active');
		if (oldActive) {
			oldActive.classList.remove('dhc-active');
		}
		opDom.classList.add('dhc-active');
		var index = parseInt(parentNode.id.split('-')[1])
		var nurseAns = opDom.querySelector('.opName').getAttribute('data-op');
		queDict[index]['Result'] = nurseAns
		if (!isAnaly) {
			$('#item-'+index)[0].classList.remove('notAns')
		}
		if (index == pageCount-1) {
			mui.toast('已经是最后一题了')
		}else{
			$("#slider").slider().nextItem();
		}
	}
	
	function radioOptionAddAnaly(optionsArea,scrollDom,index){
		var oneDict = queDict[index]
		var SubAnswer = oneDict['SubAnswer']
		var error = optionsArea.querySelector('.dhc-active .opName');
		var userAns = ''
		if (error) {
			userAns = error.innerText
		}
		if (error && error.getAttribute('data-op') != SubAnswer) {
			error.innerHTML = ''
			error.classList.add('nur-error')
		}
		
		var correct = optionsArea.querySelector('.opName[data-op="'+SubAnswer+'"]');
		var correctAns = correct.innerText
		correct.innerHTML = ''
		correct.classList.add('nur-correct')
		
		scrollDom.classList.add('analysisMode')
		var analysisArea = document.createElement('div');
		analysisArea.classList.add('analysisArea');
		scrollDom.appendChild(analysisArea);
		var analysisText = oneDict['SubAnalysis'];
		html = '<div class="ansCompare">正确答案：<span class="correctAns">'+correctAns+'</span>&nbsp;&nbsp;'+
				'您的答案：<span class="yourAns">'+userAns+'</span></div>'+
			'<div class="seperateBar"></div>'+
			'<div class="analysisText">解析：<br/>'+analysisText+'</div>'
		analysisArea.innerHTML = html
	}
	
	// 多选
	function createCheckboxUI(oneDict,scrollDom,index){
		scrollDom.classList.remove('analysisMode')
		var option = oneDict['SubOption'].split('」')
		var optionsArea = document.createElement('div');
		optionsArea.id = 'ques-'+index
		optionsArea.classList.add('optionsArea');
		scrollDom.appendChild(optionsArea);
		
		var html = ''
		var nurAns = oneDict['Result'] 
		for(var i= 0; i < option.length;i++){
			var op = option[i];
			var activeClass=''
			var spStr = ','
			if (nurAns.indexOf('」') != -1) {
				spStr = '」'
			}
			if(nurAns!="" && (spStr+nurAns+spStr).indexOf(spStr+i+spStr) != -1){
				activeClass='dhc-active'
			}
			var str = String.fromCharCode(64 + parseInt(i+1));
			html += '<div class="option '+activeClass+'">'+
				'<div class="opName nurfont" data-op="'+i+'">'+str+'</div>'+
				'<div class="opTitle">'+op+'</div></div>'
		}
		optionsArea.innerHTML = html;
		if (isAnaly) {//解析部分
			checkboxOptionAddAnaly(optionsArea,scrollDom,index);
			return
		}
		//确认答案
		var sureAnsBtn = document.createElement('div');
		sureAnsBtn.id = 'sure-'+index
		sureAnsBtn.classList.add('sureAnsBtn');
		sureAnsBtn.innerText = '确认答案'
		sureAnsBtn.addEventListener('tap',checkBoxSureTapped)
		scrollDom.appendChild(sureAnsBtn);
		var options = optionsArea.querySelectorAll('.option');
		for (var i = 0; i < options.length;i++) {
			options[i].addEventListener('tap',checkBoxOptionTapped);
		}
	}
	function checkBoxOptionTapped(){
		if (this.getAttribute('class').indexOf('dhc-active') != -1) {
			this.classList.remove('dhc-active');
		}else{
			this.classList.add('dhc-active');
		}
	}
	
	function checkBoxSureTapped(){
		var checkBtn = this
		//checkBtn.style.display = 'none'
		var chekIndex = checkBtn.id.split('-')[1]
		var optionsArea = checkBtn.parentNode.querySelector('.optionsArea')
		var activeDoms = optionsArea.querySelectorAll('.option.dhc-active')
		var nurAns = ''
		for (var i = 0; i < activeDoms.length;i++) {
			nurAns += activeDoms[i].querySelector('.opName').getAttribute('data-op')
			if (i != activeDoms.length - 1) {
				nurAns += splitStr
			}
		}
		if (activeDoms.length == 0) {
			mui.toast('请选择您的答案')
			return
		}
		queDict[chekIndex]['Result'] = nurAns
		if (!isAnaly) {
			$('#item-'+chekIndex)[0].classList.remove('notAns')
		}
		if (chekIndex == pageCount-1) {
			mui.toast('已经是最后一题了')
		}else{
			$("#slider").slider().nextItem();
		}
	}
	
	function checkboxOptionAddAnaly(optionsArea,scrollDom,index){
		var oneDict = queDict[index]
		var spStr = ','
		if (oneDict['Result'].indexOf('」') != -1) {
			spStr = '」'
		}
		var ResultStr = spStr+oneDict['SubAnswer']+spStr
		var errorDoms = optionsArea.querySelectorAll('.dhc-active .opName');
		var userAns = ''
		for (var i = 0; i < errorDoms.length;i++) {
			var errDom = errorDoms[i]
			userAns += errDom.innerHTML
			if (ResultStr.indexOf(spStr+errDom.getAttribute('data-op')+spStr) != -1) {
				continue
			}
			errDom.innerHTML = ''
			errDom.classList.add('nur-error')
		}
		var spStr = ','
		if (oneDict['SubAnswer'].indexOf('」') != -1) {
			spStr = '」'
		}
		var SubAnswer = oneDict['SubAnswer'].split(spStr)
		var correctAns = ''
		for (var i = 0; i < SubAnswer.length;i++) {
			var correct = optionsArea.querySelector('.opName[data-op="'+SubAnswer[i]+'"]');
			correctAns += correct.innerHTML
			correct.innerHTML = ''
			correct.classList.add('nur-correct')
		}
		scrollDom.classList.add('analysisMode')
		var analysisArea = document.createElement('div');
		analysisArea.classList.add('analysisArea');
		scrollDom.appendChild(analysisArea);
		var analysisText = oneDict['SubAnalysis'];
		html = '<div class="ansCompare">正确答案：<span class="correctAns">'+correctAns+'</span>&nbsp;&nbsp;'+
				'您的答案：<span class="yourAns">'+userAns+'</span></div>'+
			'<div class="seperateBar"></div>'+
			'<div class="analysisText">解析：<br/>'+analysisText+'</div>'
		analysisArea.innerHTML = html
	}
	
	// 填空
	function createMultiBlankUI(oneDict,scrollDom,index){
		scrollDom.classList.remove('analysisMode')
		var optionsArea = document.createElement('div');
		optionsArea.id = 'ques-'+index
		optionsArea.classList.add('optionsArea');
		scrollDom.appendChild(optionsArea);
		
		var html = ''
		var spStr = ','
		if (oneDict['Result'].indexOf('」') != -1) {
			spStr = '」'
		}
		var Result = oneDict['Result'].split(spStr)
		var SubAnswer = oneDict['SubAnswer'].split('」')
		for(var i= 0; i< SubAnswer.length;i++){
			var value = Result[i]==undefined?"":Result[i]
			html += '<div class="option"><div class="fillName">（'+(i+1)+'）</div><input type="text" value="'+value+'" /></div>'
		}
		optionsArea.innerHTML = html;
		if (isAnaly) { //解析
			blankAddAnaly(optionsArea,scrollDom,index)
			return
		}
		//确认答案
		var sureAnsBtn = document.createElement('div');
		sureAnsBtn.id = 'sure-'+index
		sureAnsBtn.classList.add('sureAnsBtn');
		sureAnsBtn.innerText = '确认答案'
		sureAnsBtn.addEventListener('tap',blankSureTapped)
		scrollDom.appendChild(sureAnsBtn);
	}
	
	function blankSureTapped(){
		var sureBtn = this
		//sureBtn.style.display = 'none'
		var blankIndex = sureBtn.id.split('-')[1]
		var optionsArea = sureBtn.parentNode.querySelector('.optionsArea')
		//console.log(sureBtn.parentNode.innerHTML)
		var blankDoms = optionsArea.querySelectorAll('.option input')
		var nurAns = ''
		var isAnsed = false
		for (var i = 0; i < blankDoms.length;i++) {
			nurAns += blankDoms[i].value
			if (blankDoms[i].value != '') {
				isAnsed = true
			}
			if (i != blankDoms.length - 1) {
				nurAns += splitStr
			}
		}
		if (!isAnsed) {
			mui.toast('请输入您的答案')
			return
		}
		queDict[blankIndex]['Result'] = nurAns
		if (!isAnaly) {
			$('#item-'+blankIndex)[0].classList.remove('notAns')
		}
		if (blankIndex == pageCount-1) {
			mui.toast('已经是最后一题了')
		}else{
			$("#slider").slider().nextItem();
		}
	}
	
	function blankAddAnaly(optionsArea,scrollDom,index){
		var oneDict = queDict[index]
		var spStr = ','
		if (oneDict['Result'].indexOf('」') != -1) {
			spStr = '」'
		}
		var nurAns = oneDict['Result'].split(spStr)
		var standAns = oneDict['SubAnswer'].split('」')
		optionsArea.style.display = 'none';
		scrollDom.classList.add('analysisMode')
		var analysisArea = document.createElement('div');
		analysisArea.classList.add('analysisArea');
		scrollDom.appendChild(analysisArea);
		//包含答案即可得分 SubAnsConFlag: "1" 区分大小写		SubAnsCaseFlag: "1"  不区分答案先后顺序 SubAnsOrderFlag: "1"
		var conFlag = oneDict['SubAnsConFlag']
		var caseFlag = oneDict['SubAnsCaseFlag']
		var orderFlag = oneDict['SubAnsOrderFlag']
		html = ''
		var inputs = optionsArea.querySelectorAll('input')
		var title = oneDict['SubDesc'];
		var arr = title.split('﹏﹏')
		var ansText = ''
		for (var i= 0; i< inputs.length;i++) {
			ansText += arr[i]
			if (i != arr.length - 1) {
				ansText += '<div class="blank">'+standAns[i]+'</div>'
			}
			var value = inputs[i].value
			html += '<div class="option"><div class="fillName">（'+(i+1)+'）</div>'+
				'<div class="fillText">'+value+'</div>';
			if (compareBlankValue(value,standAns,conFlag,caseFlag,orderFlag,i)) {
				html += '<div class="nurfont nur-correct"></div></div>'
			}else{
				html += '<div class="nurfont nur-error"></div></div>'
			}
		}
		var analysisText = oneDict['SubAnalysis']
		html += '<div class="correctFillText">正确答案：<br/>'+ansText+'</div>'+
			'<div class="seperateBar"></div>'+
			'<div class="analysisText">解析：<br/>'+analysisText+'</div>'
		analysisArea.innerHTML = html
	}
	
	function compareBlankValue(value,nurAnsArr,conFlag,caseFlag,orderFlag,index){
		//包含答案即可得分 SubAnsConFlag: "1" 区分大小写		SubAnsCaseFlag: "1"  不区分答案先后顺序 SubAnsOrderFlag: "1"
		if (caseFlag != '1') {
			value = value.toUpperCase()
			var str = nurAnsArr.join('」').toUpperCase()
			nurAnsArr = str.split('」')
		}
		if (orderFlag != '1') { //区分顺序
			var ans = nurAnsArr[index]
			if (conFlag != '1') { //完全一致
				if (value == ans) {
					return 1
				}
			}else{
				if (value.indexOf(ans) != -1) {
					return 1
				}
			}
		}else{
			var str = nurAnsArr.join('」')
			if (conFlag != '1') { //完全一致
				if (('」'+str+'」').indexOf('」'+value+'」') != -1) {
					return 1
				}
			}else{
				if (str.indexOf(value) != -1) {
					return 1
				}
			}
		}
		return 0
	}
	
	// 问答
	function createAskUI(oneDict,scrollDom,index){
		scrollDom.classList.remove('analysisMode')
		var optionsArea = document.createElement('div');
		optionsArea.id = 'ques-'+index
		optionsArea.classList.add('optionsArea');
		scrollDom.appendChild(optionsArea);
		optionsArea.innerHTML = '<textarea></textarea>';
		
		var html = ''
		var Result = oneDict['Result']
		var SubAnswer = oneDict['SubAnswer']
		if (isAnaly) { //解析
			askAddAnaly(optionsArea,scrollDom,index)
			return
		}
		//确认答案
		optionsArea.querySelector('textarea').value = oneDict['Result']
		var sureAnsBtn = document.createElement('div');
		sureAnsBtn.id = 'sure-'+index
		sureAnsBtn.classList.add('sureAnsBtn');
		sureAnsBtn.innerText = '确认答案'
		sureAnsBtn.addEventListener('tap',askSureAnsBtnTapped)
		scrollDom.appendChild(sureAnsBtn);
	}
	function askSureAnsBtnTapped(){
		var sureBtn = this
		var askIndex = sureBtn.id.split('-')[1]
		var textarea = sureBtn.parentNode.querySelector('textarea')
		var nurAns = textarea.value
		if (nurAns == '') {
			mui.toast('请输入您的答案')
			return
		}
		queDict[askIndex]['Result'] = nurAns
		if (!isAnaly) {
			$('#item-'+askIndex)[0].classList.remove('notAns')
		}
		if (askIndex == pageCount-1) {
			mui.toast('已经是最后一题了')
		}else{
			$("#slider").slider().nextItem();
		}
	}
	function askAddAnaly(optionsArea,scrollDom,index){
		//解析部分
		var oneDict = queDict[index]
		var nurAns = oneDict['Result']
		var standAns = oneDict['SubAnswer']
		scrollDom.classList.add('analysisMode')
		var analysisArea = document.createElement('div');
		analysisArea.classList.add('analysisArea');
		scrollDom.appendChild(analysisArea);
		html = '<div class="yourAskText">'+nurAns+'</div>'+
			'<div class="correctAskText">参考答案：<br/>'+standAns+'</div>'+
			'<div class="seperateBar"></div>'+
			'<div class="analysisText">解析：<br/>'+oneDict['SubAnalysis']+'</div>'+
			'<div class="textTip">批注：</div>'+
			'<div class="notes">'+'缺少批注'+'</div>'+
			'<div class="textTip">分数：<div class="askScore">'+oneDict['GetScore']+'</div>分</div>'
		analysisArea.innerHTML = html
	}

	function baseSetup(){
		$('.mui-scroll-wrapper').scroll({
			bounce: true,
			indicators: false, //是否显示滚动条
		});
		// 监听滚动
		$('#slider')[0].addEventListener('slide',sliderSlidAction);
		//去考核
		mui('#examineInfo').on('tap','#toExamBtn',getExamineData) 
		// 底部的交卷按钮
		$('.mui-content .btnArea .baseBtn')[0].addEventListener('tap',function(){
			clearInterval(timer)
			$('#dhcBackdrop')[0].classList.add('dhc-active');
			$('#commitPopo')[0].classList.add('mui-active');
		})
		// 交卷弹框中的取消按钮
		$('.commitPopo .cancenBtn')[0].addEventListener('tap',function(){
			$('#dhcBackdrop')[0].classList.remove('dhc-active');
			$('#commitPopo')[0].classList.remove('mui-active');
			setupTimer()
		})
		// 底部的结束按钮
		$('.mui-content .btnArea .finishBtn')[0].addEventListener('tap',function(){
			backBtnTapped();
		})
		// 交卷弹框中的题号
		mui('.commitPopo').on('tap','.oneItem',jumpToPage) 
		$.back = backBtnTapped;
		//解析
		mui('#scoreInfo').on('tap','.examAnalyBtn',examAnalyBtnTapped) 
		var self = plus.webview.currentWebview()
		examInfo = self.sourceData;
		pageType = self.pageType;
		fromPage = self.fromPage;
		typeFlag = self.typeFlag
		var perInfo = app.getState()
		nurseid = perInfo['loginPerID']
		if (fromPage == 'toTrain') {
			if (self.isAnaly) {
				isAnaly = true
				allAnaly = self.allAnaly
				document.body.classList.add('notTiming')
			}else{
				$('#backBtn')[0].style.display = 'none'
			}
			// 交卷弹框中的确定按钮
			$('.commitPopo .sureBtn')[0].addEventListener('tap',saveToTrainClass)
			if (pageType == 'practice') { //随堂练习
				$('.mui-title')[0].innerHTML = '随堂练习'
				updateToTrainUI(examInfo['ClassDuration'])
			}else{ //结课考核 classEndExam
				$('.mui-title')[0].innerHTML = '结课考核'
				updateToTrainUI(examInfo['ResultDuration'])
			}
			//$('.mui-content .btnArea .finishBtn')[0].style.display = 'none'
			getExamineData()
			return
		}
		$('.commitPopo .sureBtn')[0].addEventListener('tap',saveAllAnswer)
		rw = examInfo['rw'];
		if (fromPage == 'examReal') {
			splitStr = ','
		}
		if (fromPage == 'toExamine') {
			isAnaly = self.isAnaly
			if (isAnaly) {
				document.body.classList.add('notTiming')
			}
		}
		var reduceTime = $('#reduceTime')[0]
		reduceTime.innerHTML = minutesToHourMinutsSecond(examInfo['Duration'])
		reduceTime.setAttribute('data-init',reduceTime.innerText);
		getExamineData()

		//mui('body').on('tap','#backBtn',backBtnTapped) 
	}
	function backBtnTapped(){
		if (!isAnaly) { //不是解析状态
			if (fromPage == 'toTrain') {
				return
			}
			mui.confirm('是否放弃已答题目?','温馨提示',['继续答题','放弃'],function (e) {
				if (e.index == 1) {
					var fromWebview = plus.webview.getWebviewById(fromPage)
					if (fromPage != 'toExamine') {
						fromWebview.evalJS("refreshPageData()")
					}
					plus.webview.currentWebview().close();
				}
			})
		}else{
			var fromWebview = plus.webview.getWebviewById(fromPage)
			if (fromPage != 'toExamine' && fromPage != 'toTrain') {
				fromWebview.evalJS("refreshPageData()")
			}
			plus.webview.currentWebview().close();
		}
		
	}
	//随堂练习
	function updateToTrainUI(timeStr){
		if (!isAnaly) {
			var reduceTime = $('#reduceTime')[0]
			reduceTime.innerHTML = minutesToHourMinutsSecond(timeStr)
			reduceTime.setAttribute('data-init',reduceTime.innerText);
		}
	}
	
	function updateCommitPopoUI(count){
		var html = ''
		for (var i=0; i < count;i++) {
			html += '<div class="oneItem notAns" id="item-'+i+'">'+(i + 1)+'</div>'
		}
		$('#commitScroll')[0].innerHTML = html
	}
	function updateSliderUI(index){
		var loop = $('#loop')[0]
		var currPageDom = $('#'+(currPage-1))[0]
		var nextPageDom = currPageDom.nextElementSibling
		var prePageDom = currPageDom.previousElementSibling
		currPageDom.classList.remove('mui-active')
		if (currPage < index + 1) { //下一题
			if (currPage == 1 || currPage == pageCount - 1) { //第一页滑到第二页  滑到最后一页
				if (currPage == pageCount - 1) {
					currSlideIndex = 2;
				}else{
					currSlideIndex = 1;
				}
				currPage = index + 1;
				$('#currPage')[0].innerHTML = currPage;
				nextPageDom.classList.add('mui-active')
				return
			}
			loop.removeChild(prePageDom)
			updateOneQuesUI(index+1)
		}else { //上一题
			if(index == 0){
				currSlideIndex = 0;
				currPage = index + 1;
				$('#currPage')[0].innerHTML = currPage;
				prePageDom.classList.add('mui-active')
				return
			}
			if (currPage == pageCount) { //滑到倒数第二页
				currSlideIndex = 1;
				currPage = index + 1;
				$('#currPage')[0].innerHTML = currPage;
				prePageDom.classList.add('mui-active')
				return
			}
			prePageDom.classList.add('mui-active')
			loop.removeChild(nextPageDom)
			updateOneQuesUI(index-1,prePageDom)
		}
		currSlideIndex = 1;
		currPage = index + 1;
		$('#currPage')[0].innerHTML = currPage;
		mui('#slider').slider().refresh();
		$('#slider')[0].removeEventListener('slide',sliderSlidAction);
		mui('#slider').slider().gotoItem(currSlideIndex,0);
		$('#slider')[0].addEventListener('slide',sliderSlidAction);
	}
	
	function jumpToPage(){
		clearAllBtnTapped()
		$('#loop')[0].innerHTML = ''
		currPage = parseInt(this.innerText)
		var index = currPage - 1
		var start = index - 1
		currSlideIndex = 1;
		if (currPage == 1) {
			currSlideIndex = 0
			start=0
		}else if (currPage == pageCount) {
			currSlideIndex = 2
			start = index-2
		}
		for(var i = start; i < start+3;i++){
			updateOneQuesUI(i)
		}
		if ($('#'+index)[0]) {
			$('#'+index)[0].classList.add('mui-active')
		}
		if (!isAnaly) {
			if ($('#commitScroll .dhc-active')[0]) {
				$('#commitScroll .dhc-active')[0].classList.remove('dhc-active')
			}
			$('#item-'+index)[0].classList.add('dhc-active')
		}
		
		mui('#slider').slider().refresh();
		$('#slider')[0].removeEventListener('slide',sliderSlidAction);
		mui('#slider').slider().gotoItem(currSlideIndex,0);
		$('#slider')[0].addEventListener('slide',sliderSlidAction);
		$('#currPage')[0].innerHTML = currPage;
		mui.trigger($('#commitPopo .cancenBtn')[0],'tap');
	}

	function sliderSlidAction(){
		var index = event.detail.slideNumber;
		var newPage = ''
		if (index > currSlideIndex) {
			newPage = currPage + 1
		}else{
			newPage = currPage - 1
		}
		if (!isAnaly) {
			if ($('#commitScroll .dhc-active')[0]) {
				$('#commitScroll .dhc-active')[0].classList.remove('dhc-active')
			}
			$('#item-'+(newPage-1))[0].classList.add('dhc-active')
		}
		updateSliderUI(newPage-1)
	}
	
	function setupTimer(){
		if (timer) {
			clearInterval(timer)
		}
		timer = setInterval(function() {
			var timeBtn =  $('#reduceTime')[0];
			timeBtn.innerText = hourMinuteSecondReduce(timeBtn.innerText);
			if (timeBtn.innerText == '00:00:00') {
				clearInterval(timer)
				var commitPopo = $('#commitPopo')[0];
				commitPopo.classList.add('forceCommit');
				if (commitPopo.getAttribute('class').indexOf('mui-active') == -1) {
					$('#dhcBackdrop')[0].classList.add('dhc-active');
					commitPopo.classList.add('mui-active');
				}
			}
		}, 1000);
	}
	function updateScoreInfo(){
		document.body.classList.add('notTiming')
		var score = 0
		var count = 0
		var ReleasePass = parseInt(examInfo['ReleasePass'])
		var html = '<div class="scoreTitle">考试成绩</div>'
		for (var i = 0; i < queDict.length;i++) {
			var oneDict = queDict[i]
			var type = oneDict['SubMode']
			var GetScore = parseInt(oneDict['GetScore'])
			var ExamScore = oneDict['ExamScore']
			if (ExamScore != oneDict['GetScore']) {
				count++
			}
			if (!isNaN(GetScore)) {
				score += GetScore
			}
		}
		//console.log(JSON.stringify(queDict))
		if (ReleasePass > score) {
			html += '<div class="scoreResult redColor">未通过</div>'
		}else{
			html += '<div class="scoreResult">通过</div>'
		}
		html += '<div class="scoreText">'+score+'<span >分</span></div>'+
			'<div class="scoreCount">答对'+(queDict.length - count)+'道题，答错'+count+'道题，用时 '+examInfo['ExamTime']+'</div>'+
			'<div class="examAnalyBtns">'+
				'<div class="mui-btn mui-btn-primary examAnalyBtn">查看错误解析</div>'+
				'<div class="mui-btn mui-btn-primary examAnalyBtn">查看所有解析</div>'+
			'</div>'
		mui('#scoreInfo').off('tap','.examAnalyBtn',examAnalyBtnTapped) 
		$('#scoreInfo')[0].innerHTML = html;
		mui('#scoreInfo').on('tap','.examAnalyBtn',examAnalyBtnTapped) 
		$('#dhcBackdrop')[0].classList.remove('dhc-active');
		$('#commitPopo')[0].classList.remove('mui-active');
		$('#scoreInfo')[0].style.display = 'block'
		
		mui.trigger(mui('.commitPopo .oneItem')[0],'tap')
	}
	
	function examAnalyBtnTapped(){
		clearAllBtnTapped()
		$('#loop')[0].innerHTML = ''
		currSlideIndex = 0;
		currPage = 1;
		$('#scoreInfo')[0].style.display = 'none'
		isAnaly = true
		if (this.innerText != '查看错误解析') {
			allAnaly = true
		}
		updateExamUI()
	}
	function clearAllBtnTapped(idStr){
		idStr = idStr==undefined?'':('#'+idStr + ' ')
		//单选
		mui(idStr+'.mui-scroll[data-type="S"] .').each(function (index,element) {
			element.removeEventListener('tap',radioOptionTapped); 
		})
		//多选
		mui(idStr+'.mui-scroll[data-type="M"] .option').each(function (index,element) {
			element.removeEventListener('tap',checkBoxOptionTapped); 
		})
		mui(idStr+'.mui-scroll[data-type="M"] .sureAnsBtn').each(function (index,element) {
			element.removeEventListener('tap',checkBoxSureTapped); 
		})
		//填空
		mui(idStr+'.mui-scroll[data-type="B"] .sureAnsBtn').each(function (index,element) {
			element.removeEventListener('tap',blankSureTapped);
		})
		//问答
		mui(idStr+'.mui-scroll[data-type="B"]').each(function (index,element) {
			element.removeEventListener('tap',askSureAnsBtnTapped);
		})
	}
})(mui);

/*
包含答案即可得分 SubAnsConFlag: "1"
区分大小写		SubAnsCaseFlag: "1"
不区分答案先后顺序 SubAnsOrderFlag: "1"

{"rw":"24","AnswerDate":"","AnswerTime":"","CreatDate":"2022-09-21","CreatTime":"17:54","Creator":"1","Duration":"50",
"ExamScore":"","ExamTime":"","PaperType":"I","RealPaperType":"I","ReleaseDesc":"测试0921","ReleasePaper":"","ReleasePass":"30",
"Score":"100","Status":"N","ReleaseType":"54||1","ReleaseTypeDesc":"三基","QuestRange":"S」」10」10」100」1,5","StatusDesc":"未答题",
"SubSum":"10","53__1":"10"}]

真题模考
ClassName: web.INMTeaComm
MethodName: SaveLearnDryRunSub
MethodType: Method
APPLoginID: 338
APPPerID: 338
parr: 7||1「0111「0」7||2「01「0」7||3「01「0」7||4「0「0」7||5「01「0」7||6「0111111111「1,2,3」7||7「01111111111111111「1,2」7||8「011111「0,1,2」7||9「011111「0,1
rw: 7
ExamTime: 00:00:41

返回值1^0,1,1,0,1,0,0,1,0

*/